use common::file_system::write_to_file;
use common::model::{CodeModule, LibImport};
use common::traits::CommonModuleTrait;
use std::fs;
use std::path::Path;

pub fn init_import(
    module_file_path: &str,
    lib_imports: &[LibImport],
) -> Result<(), Box<dyn std::error::Error>> {
    let mut code_module = CodeModule::new(&fs::read_to_string(module_file_path)?)?;
    for import in lib_imports {
        code_module.init_import(import)?;
    }
    write_to_file(Path::new(module_file_path), &code_module.get_source())?;
    Ok(())
}
